<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
    <title>稻道工场 社区粮店</title>
    <link rel="stylesheet" href="/thinkphp/Public/home/css/reset.css" />
    <link rel="stylesheet" href="/thinkphp/Public/home/css/store.css" />
    <script type="text/javascript" src="/thinkphp/Public/home/js/zepto.min.js" ></script>
    <script src="/thinkphp/Public/home/js/swiper.min.js"></script>
</head>


	<body>
		<div class="layout">
			<!--header-->
			<div class="wrapper">
				<div class="header">
					<a class="s_preson" href="<?php echo U('Users/index');?>" target="_blank"><i class="s_icon s_author"></i></a>
                    <form action="<?php echo U('Index/index');?>" method='POST'>
                        <div class="store">
                            <select style="text-align: right;" class="select" name="sellerID" onchange="subSellerName()">
                                <?php if(($sellerName == '')): ?><option value="">-- 请选择 --</option>
                                <?php else: ?>
                                    <option><?php echo ($sellerName); ?></option><?php endif; ?>
                                <?php if(is_array($businessFull)): $i = 0; $__LIST__ = $businessFull;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$co): $mod = ($i % 2 );++$i;?><option value="<?php echo ($co["id"]); ?>"><?php echo ($co["nick"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
                            </select>
                            <input type="submit" value="ok" id="subSN" style="display:none;"/>
                            <label>﹀</label>
                        </div>
                    </form>
					<div class="s_search">
                        <a href="<?php echo U('Search/index');?>">
						    <i class="s_icon s_searchBtn"></i>
                        </a>
					</div>
				</div>
			</div>
			<script>
                function subSellerName()
                {
                    $("#subSN").trigger("click");
                }
            </script>
			<!--幻灯片-->
			<div class="swiper-container">
		        <div class="swiper-wrapper">
		            <div class="swiper-slide"><a href="#" target="_blank"><img src="/thinkphp/Public/home/img/banner.jpg" alt="" title=""/></a></div>
		            <div class="swiper-slide"><a href="#" target="_blank"><img src="/thinkphp/Public/home/img/banner.jpg" alt="" title=""/></a></div>
		            <div class="swiper-slide"><a href="#" target="_blank"><img src="/thinkphp/Public/home/img/banner.jpg" alt="" title=""/></a></div>
		        </div>
		        <div class="swiper-pagination"></div>
		    </div>
			
			<div class="storeMain clearfix">
				<ul class="storeNav">
					<!--<li class="cur">大米 <span class="tips">新</span><i class="num">1</i></li>-->
                    <?php if(is_array($cate)): $i = 0; $__LIST__ = $cate;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$ro): $mod = ($i % 2 );++$i;?><!--<li><?php echo ($ro["name"]); ?><span class="tips">新</span><i class="num">1</i></li>-->
                        <li>
                            <?php echo ($ro["name"]); ?>
                                <i class="num"><?php echo ($ro["sumCartNum"]); ?></i>
                        </li><?php endforeach; endif; else: echo "" ;endif; ?>
                    <li>
                        店长推荐
                        <i class="num"></i>
                    </li>
				</ul>
				<!--第一个循环-->
                <?php if(is_array($product)): $i = 0; $__LIST__ = $product;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><div class="storeBox">
                    <?php if(is_array($vo)): $i = 0; $__LIST__ = $vo;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$ro): $mod = ($i % 2 );++$i;?><div class="list-item">
                            <div class="list-img"><a href="<?php echo U('Good/GoodInfo',array('id'=>$ro[id]));?>"><img src="/thinkphp/Uploads/thumb/<?php echo ($ro["thumb"]); ?>" alt="" width="80" /></a></div>
                            <div class="list-content">

                                <a href="<?php echo U('Good/GoodInfo',array('id'=>$ro[id]));?>"><h3 class="list-title"><?php echo ($ro["name"]); ?></h3></a>
                                <p class="list-price"><em>￥<?php echo ($ro["shop_price"]); ?></em>&nbsp;</p>
                                <?php if(($ko[promote_price] > '0')): ?><div class="list-main">微信支付<span>立减<i><?php echo ($ko["promote_price"]); ?></i>元</span></div><?php endif; ?>
                                <div class="list-add">
                                    <em class="prev" data="<?php echo ($ro["id"]); ?>" style="display: inline-block;">-</em>
                                    <?php if($ro[cart_number] != '0'): ?><input style="display:inline-block; background: #FFFFFF;" type="text" size="5" value="<?php echo ($ro["cart_number"]); ?>" disabled="disabled"><?php endif; ?>
                                    <em class="next" data="<?php echo ($ro["id"]); ?>" style="border:1px solid #FF0000;">+</em>
                                </div>
                            </div>
                        </div><?php endforeach; endif; else: echo "" ;endif; ?>
				</div><?php endforeach; endif; else: echo "" ;endif; ?>
				<!--第二个循环-->
				<div class="storeBox">
                    <?php if(is_array($sellerProduct)): $i = 0; $__LIST__ = $sellerProduct;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$ko): $mod = ($i % 2 );++$i;?><div class="list-item">
                            <div class="list-img"><a href="<?php echo U('Good/GoodInfo',array('id'=>$ko[id]));?>"><img src="/thinkphp/Uploads/seller/thumb/<?php echo ($ko["thumb"]); ?>" width="80" alt="" /></a></div>
                            <div class="list-content">
                                <a href="<?php echo U('Good/GoodInfo',array('id'=>$ko[id]));?>"><h3 class="list-title"><?php echo ($ko["name"]); ?></h3></a>
                                <p class="list-price"><em>￥<?php echo ($ko["shop_price"]); ?></em>&nbsp;</p>

                                <div class="list-main">微信支付<span>立减<i><?php echo ($ko["promote_price"]); ?></i>元</span></div>

                                <div class="list-add">
                                    <em class="prev" data="<?php echo ($ko["id"]); ?>" style="display:inline-block">-</em>
                                        <input style="display:inline-block;" type="text" size="5" value="<?php echo ($ko["cart_number"]); ?>">
                                    <em class="next" data="<?php echo ($ko["id"]); ?>">+</em>
                                </div>
                            </div>
                        </div><?php endforeach; endif; else: echo "" ;endif; ?>
				</div>
			</div>
		
			<div class="addUp">
				<div class="s_shopping"><i class="s_icon s_up"></i><em id="cartNum"><?php echo ($cartNum); ?></em></div>
				<div class="total">总计:<p>￥<em id="cartPrice"><?php echo ($cartPrice); ?></em></p></div>
				<div class="settlement"><a style="color:#FFFFFF" href="<?php echo U('Order/cart');?>">去结算</a></div>
			</div>
		</div>
	</body>
</html>

<script type="text/javascript">
    $(document).ready(
        function(){
            $('.num').each(
                function(){
                    if($(this).text()<="0")
                    {
                        $(this).hide();
                    }
                }
            );

            var storeBox = $('.storeBox');
            var storeNav = $('.storeNav');

            for(var i=0;i<=storeBox.length;i++)
            {
                var input=storeBox.eq(i).find('input');
                var yanG="";
                for(var j=0;j<=input.length;j++)
                {
                    var yanG1=parseInt(input.eq(j).val());

                    if(yanG1!="undefined")
                    {
                        if(!isNaN(yanG1))
                        {
                            yanG=parseInt(yanG+yanG1);
                        }
                    }
                }

                storeNav.find(".num").eq(i).html(yanG);
                if(yanG<="0")
                {
                    storeNav.find(".num").eq(i).hide();
                }else{
                    storeNav.find(".num").eq(i).show();
                }
            }



            numHide();
        }
    );

    function numHide()
    {

        $('.prev').each(
                function(){

                    var aa = $(this).next("input").val();
                    var bb = parseInt(aa);
                    if(isNaN(bb)||bb==0)
                    {
                        $(this).hide();
                    }
//                    if($(this).text()<=0||isNaN($(this).text()))
//                    {
//                        $(this).hide();
//                    }
                }
        );
    }
//幻灯片
var swiper = new Swiper('.swiper-container', {
    pagination: '.swiper-pagination',
    paginationClickable: true,
    autoplay: 2500,
    loop: true
});

$('.storeMain .storeNav li').click(function(){
	var index = $(this).index();
	show(index);
});

show(0);
function show(index){
	$('.storeMain .storeNav li').removeClass('cur').eq(index).addClass('cur');
	$('.storeBox').hide().eq(index).show();
}

//商品加减统计
var listItem = $('.list-content');
var listAdd  = listItem.find('.list-add');
for(var i=0;i<listItem.length;i++){
	fnMain(listItem.eq(i));
};
		
function fnMain(quantityCur){
	var oPrev = quantityCur.find('.prev');
	var oNext  =   quantityCur.find('.next');
	var formInput =   quantityCur.find('input');
	var num = formInput.val();

//	var num=0;

	function showHide(){
		if(num==0||isNaN(num)){
			oPrev.css({'display':'none'});
			formInput.css({'display':'none'});
		}else{
			oPrev.css({'display':'inline-block'});
			formInput.css({'display':'inline-block'});
		}
	}


	oPrev.click(function(){
		if(num>0){
			num--;
		};
		showHide();
		formInput.val(num);
        var productID=oPrev.attr("data");
        var number=num;
        $.ajax({
            url:"<?php echo U('Index/addCart');?>",

            type: 'POST',

            data:{
                productID:productID,
                number:number
            },

            dataType: 'html',

            timeout: 1000,

//            error: function(){alert('Error loading PHP document');},

            success: function(result){
                var one=result.split("/");
                $("#cartNum").html(one[0]);
                $("#cartPrice").html(one[1]);
            }

        });

        updataCate();
	});
	oNext.click(function(){
		num++;
		showHide();
		formInput.val(num);
        var productID=oNext.attr("data");
        var number=num;
        $.ajax({
            url:"<?php echo U('Index/addCart');?>",

            type: 'POST',

            data:{
                productID:productID,
                number:number
            },

            dataType: 'html',

            timeout: 1000,

//            error: function(){alert('Error loading PHP document');},

            success: function(result){
                var one=result.split("/");
                $("#cartNum").html(one[0]);
                $("#cartPrice").html(one[1])
            }

        });

        updataCate();
	});

    function updataCate()
    {
        var storeBox = $('.storeBox');
        var storeNav = $('.storeNav');


        for(var i=0;i<=storeBox.length;i++)
        {
            var input=storeBox.eq(i).find('input');
            var yanG="";
            for(var j=0;j<=input.length;j++)
            {
                var yanG1=parseInt(input.eq(j).val());

                if(yanG1!="undefined")
                {
                    if(!isNaN(yanG1))
                    {
                        yanG=parseInt(yanG+yanG1);
                    }
                }
            }

            storeNav.find(".num").eq(i).html(yanG);
            if(yanG<="0")
            {
                storeNav.find(".num").eq(i).hide();
            }else{
                storeNav.find(".num").eq(i).show();
            }
        }
    }
};

</script>

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

</body>
</html>